﻿// Decompiled with JetBrains decompiler
// Type: UnityEngine.Color32
// Assembly: UnityEngine.CoreModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
// MVID: E6AE6B5A-2752-4B07-9528-C8B77C62CE79
// Assembly location: C:\Users\windys\Unity\2021.3.39f1c1\Editor\Data\Managed\UnityEngine\UnityEngine.CoreModule.dll
// XML documentation location: C:\Users\windys\Unity\2021.3.39f1c1\Editor\Data\Managed\UnityEngine\UnityEngine.CoreModule.xml

using System;
using System.Globalization;
using System.Runtime.InteropServices;
using UnityEngine.Scripting;

#nullable disable
namespace UnityEngine
{
  /// <summary>
  ///   <para>Representation of RGBA colors in 32 bit format.</para>
  /// </summary>
  [StructLayout(LayoutKind.Explicit)]
  /// <summary>
  ///   <para>Constructs a new Color32 with given r, g, b, a components.</para>
  /// </summary>
  /// <param name="r"></param>
  /// <param name="g"></param>
  /// <param name="b"></param>
  /// <param name="a"></param>
  public struct Color32(byte r, byte g, byte b, byte a) : IFormattable
  {
    [FieldOffset(0)]
    private int rgba = 0;
    /// <summary>
    ///   <para>Red component of the color.</para>
    /// </summary>
    [FieldOffset(0)]
    public byte r = r;
    /// <summary>
    ///   <para>Green component of the color.</para>
    /// </summary>
    [FieldOffset(1)]
    public byte g = g;
    /// <summary>
    ///   <para>Blue component of the color.</para>
    /// </summary>
    [FieldOffset(2)]
    public byte b = b;
    /// <summary>
    ///   <para>Alpha component of the color.</para>
    /// </summary>
    [FieldOffset(3)]
    public byte a = a;

    public static implicit operator Color32(Color c)
    {
      return new Color32((byte) Mathf.Round(Mathf.Clamp01(c.r) * (float) byte.MaxValue), (byte) Mathf.Round(Mathf.Clamp01(c.g) * (float) byte.MaxValue), (byte) Mathf.Round(Mathf.Clamp01(c.b) * (float) byte.MaxValue), (byte) Mathf.Round(Mathf.Clamp01(c.a) * (float) byte.MaxValue));
    }

    public static implicit operator Color(Color32 c)
    {
      return new Color((float) c.r / (float) byte.MaxValue, (float) c.g / (float) byte.MaxValue, (float) c.b / (float) byte.MaxValue, (float) c.a / (float) byte.MaxValue);
    }

    /// <summary>
    ///   <para>Linearly interpolates between colors a and b by t.</para>
    /// </summary>
    /// <param name="a"></param>
    /// <param name="b"></param>
    /// <param name="t"></param>
    public static Color32 Lerp(Color32 a, Color32 b, float t)
    {
      t = Mathf.Clamp01(t);
      return new Color32((byte) ((double) a.r + (double) ((int) b.r - (int) a.r) * (double) t), (byte) ((double) a.g + (double) ((int) b.g - (int) a.g) * (double) t), (byte) ((double) a.b + (double) ((int) b.b - (int) a.b) * (double) t), (byte) ((double) a.a + (double) ((int) b.a - (int) a.a) * (double) t));
    }

    /// <summary>
    ///   <para>Linearly interpolates between colors a and b by t.</para>
    /// </summary>
    /// <param name="a"></param>
    /// <param name="b"></param>
    /// <param name="t"></param>
    public static Color32 LerpUnclamped(Color32 a, Color32 b, float t)
    {
      return new Color32((byte) ((double) a.r + (double) ((int) b.r - (int) a.r) * (double) t), (byte) ((double) a.g + (double) ((int) b.g - (int) a.g) * (double) t), (byte) ((double) a.b + (double) ((int) b.b - (int) a.b) * (double) t), (byte) ((double) a.a + (double) ((int) b.a - (int) a.a) * (double) t));
    }

    public byte this[int index]
    {
      get
      {
        switch (index)
        {
          case 0:
            return this.r;
          case 1:
            return this.g;
          case 2:
            return this.b;
          case 3:
            return this.a;
          default:
            throw new IndexOutOfRangeException("Invalid Color32 index(" + index.ToString() + ")!");
        }
      }
      set
      {
        switch (index)
        {
          case 0:
            this.r = value;
            break;
          case 1:
            this.g = value;
            break;
          case 2:
            this.b = value;
            break;
          case 3:
            this.a = value;
            break;
          default:
            throw new IndexOutOfRangeException("Invalid Color32 index(" + index.ToString() + ")!");
        }
      }
    }

    internal bool InternalEquals(Color32 other) => this.rgba == other.rgba;

    /// <summary>
    ///   <para>Returns a formatted string for this color.</para>
    /// </summary>
    /// <param name="format">A numeric format string.</param>
    /// <param name="formatProvider">An object that specifies culture-specific formatting.</param>
    public override string ToString() => this.ToString((string) null, (IFormatProvider) null);

    /// <summary>
    ///   <para>Returns a formatted string for this color.</para>
    /// </summary>
    /// <param name="format">A numeric format string.</param>
    /// <param name="formatProvider">An object that specifies culture-specific formatting.</param>
    public string ToString(string format) => this.ToString(format, (IFormatProvider) null);

    /// <summary>
    ///   <para>Returns a formatted string for this color.</para>
    /// </summary>
    /// <param name="format">A numeric format string.</param>
    /// <param name="formatProvider">An object that specifies culture-specific formatting.</param>
    public string ToString(string format, IFormatProvider formatProvider)
    {
      if (formatProvider == null)
        formatProvider = (IFormatProvider) CultureInfo.InvariantCulture.NumberFormat;
      return string.Format("RGBA({0}, {1}, {2}, {3})", (object) this.r.ToString(format, formatProvider), (object) this.g.ToString(format, formatProvider), (object) this.b.ToString(format, formatProvider), (object) this.a.ToString(format, formatProvider));
    }
  }
}
